package cn.zwk.excel;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 解析后的行：包含key及该行所有语句。
 * 当存在跳过原因时，该行视为无效（不参与请求）。
 */
public final class ParsedRow {
    private final int rowIndex; // 0-based
    private final String key;
    private final List<QueryItem> queries;
    private final List<SkipReason> skipReasons;

    public ParsedRow(int rowIndex, String key, List<QueryItem> queries, List<SkipReason> skipReasons) {
        this.rowIndex = rowIndex;
        this.key = key;
        this.queries = queries == null ? List.of() : List.copyOf(queries);
        this.skipReasons = skipReasons == null ? List.of() : List.copyOf(skipReasons);
    }

    public int rowIndex() {
        return rowIndex;
    }

    public String key() {
        return key;
    }

    public List<QueryItem> queries() {
        return Collections.unmodifiableList(queries);
    }

    public List<SkipReason> skipReasons() {
        return Collections.unmodifiableList(skipReasons);
    }

    public boolean isSkipped() {
        return !skipReasons.isEmpty();
    }

    public ParsedRow withAdditionalQuery(QueryItem item) {
        List<QueryItem> copy = new ArrayList<>(this.queries);
        copy.add(item);
        return new ParsedRow(this.rowIndex, this.key, copy, this.skipReasons);
    }
}

